export default {
	async uploadFile(tempFile,imageType="image",storageKey='avatar'){
		return await this.$netTool.handleUploadFile(
			this.absUrl('/api/common/storage/upload'),  //上传接口URL
			tempFile, // 要上传的文件路径
			imageType, //文件类型
			storageKey, // 存储关键字,存储目录名称
			{
				"token":this.userStore.token //headers 加上令牌
			},
		);
	}, 
	async chooseImageToUpload(){
		return new Promise((resolve,reject)=>{
			uni.chooseImage({
				count: 1,
				success: async (res)=>{
					console.log(JSON.stringify(res.tempFilePaths));
					let result = await this.uploadFile(res.tempFilePaths[0])
					console.log(result)
					resolve(result.data.path)
				}
			})
		})
	},
	async chooseVideoToUpload(){
		let that = this
		return new Promise((resolve,reject)=>{
			uni.chooseVideo({
				sourceType: ['camera', 'album'],
				success: async function (res) {
					console.log(JSON.stringify(res.tempFilePath));
					let result = await that.uploadFile(res.tempFilePath,'video')
					console.log(result)
					resolve(result.data.path)
				}
			})
		})
	}
}